﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Class_Entity;
using BussinessObject;

public partial class WebApplication_ADContactUs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            loadGrid();

        }
    }


    private void loadGrid()
    {
        ContactUs cu = new ContactUs();
        BOContactUs bocu = new BOContactUs();

        GridView1.DataSource = bocu.Load_ContactUs(cu);
        GridView1.DataBind();
    }

    protected void btNew_Click(object sender, EventArgs e)
    {
        Response.Redirect("ADAddContactUs.aspx");
    }


    protected void btSearch_Click(object sender, EventArgs e)
    {
        ContactUs cu = new ContactUs();
        BOContactUs bocu = new BOContactUs();

        cu.BranchName = txtSearch.Text;

        GridView1.DataSource = bocu.Search_ContactUs(cu);
        GridView1.DataBind();
    }


    protected void btDelete_Click(object sender, EventArgs e)
    {
        ContactUs cu = new ContactUs();
        BOContactUs bocu = new BOContactUs();


        foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
            if (cb != null && cb.Checked)
            {

                int id = Convert.ToInt32(row.Cells[1].Text);
                cu.ID = id;
                bocu.Deletet_ContactUs(cu);

            }
        }

        loadGrid();
    }


    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        ContactUs cu = new ContactUs();
        BOContactUs bocu = new BOContactUs();

        int id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[1].Text);

        cu.ID = id;

        bocu.Deletet_ContactUs(cu);

        loadGrid();
    }


    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["ID"] = Convert.ToInt32(GridView1.SelectedRow.Cells[1].Text);
        Response.Redirect("ADEditContactUs.aspx");
    }
}